package Util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class BaseMapper {
    private final static String RESOURCE = "Config/MybatisConfig.xml";//改成自己的mybatiscofig配置文件路径
    public static SqlSession getSqlSession(){
        SqlSession sqlSession=null;
        try {
            InputStream inputStream = Resources.getResourceAsStream(RESOURCE);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            //2.获取sqlsession对象,内部参数true为自动提交事务false为不自动
            sqlSession = sqlSessionFactory.openSession(true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sqlSession;
    }
}
